package org.grayrabbit.cms.plugin.loaders;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.dom4j.Element;

public class LoaderUtils {

	public static Map<String, String> getParams(Element element) {
		List<?> elements = element.elements("param");
	    Map<String,String> params = new HashMap<String,String>(elements.size());
	    for (Iterator<?> iterator = elements.iterator(); iterator.hasNext(); )
	    {
	      Element paramEl = (Element)iterator.next();
	      String name = paramEl.attributeValue("name");
	      String value = paramEl.attributeValue("value");
	      if ((value == null) && (paramEl.getTextTrim() != null) && (!"".equals(paramEl.getTextTrim())))
	      {
	        value = paramEl.getTextTrim();
	      }
	      params.put(name, value);
	    }
	    return params;
	}

}
